package com.collection.data;

import com.motu.vertx.module.utility.toolset.Tool;
import io.vertx.core.json.JsonObject;

public class CollectionRequestInfo {
	public static final String TYPE_REGISTER = "register";//注册日志
	public static final String TYPE_LOGIN = "login";//登录日志
	public static final String TYPE_CHARGE = "charge";//充值日志

	private String accountId;
	private long userId;
	private int platform;
	private int channel;
	private int serverId;

	//	public String deviceId;
	private String orderId;
	private double money;
	private String logType;
	private String ip;
	private String idfa = "";
	private String idfv = "";
	private String imei = "";
	private String oaid = "";//安卓设备匿名标识符，详情参见：http://msa-alliance.cn/col.jsp?id=120
	private String androidid = "";
	private String ryos = "";
	private String ua = "";
	private String caid = "";//最新caid
	private String last_caid = "";//上个版本caid
	private String deviceTypeAd = "";//客户端MotuSdk 广告中台-设备id
	private String deviceidAd = "";//客户端MotuSdk 广告中台-设备id类型
	private String deviceidBi = "";//客户端MotuSdk 数数中台-设备id


	private String eventName = "";


	public CollectionRequestInfo(String logType, long userId, String accountId, int serverId, long userExtChannel, int userExtPlatform, String mtDeviceInfo, String ip,JsonObject gobj){
		this.accountId = accountId;
		this.userId = userId;
		this.serverId = serverId;

		this.logType = logType;


		if(gobj != null) {
			this.platform = gobj.getInteger("platform",0);
			this.channel = gobj.getInteger("channel",0);
			this.ip = gobj.getString("ip",ip);
			this.idfa = gobj.getString("idfa","");
			this.idfv = gobj.getString("idfv","");
			this.imei = gobj.getString("imei","");
			this.androidid = gobj.getString("androidid","");
			this.oaid = gobj.getString("oaid","");
			this.ryos = gobj.getString("ryos","");
			this.ua = gobj.getString("ua","");
			this.caid = gobj.getString("caid","");
			this.last_caid = gobj.getString("last_caid","");
			this.deviceidAd = gobj.getString("device_id_mt","");
			this.deviceTypeAd = gobj.getString("device_id_type_mt","");
			this.deviceidBi = gobj.getString("device_id_bi_mt","");//获取网管对象中device_id_bi_mt - 魔兔sdk 数据中台设备id
			if(this.deviceidBi == null || this.deviceidBi.isEmpty()){
				//获取网管对象中device_id_td - 数数设备id
				this.deviceidBi = gobj.getString("device_id_td","");
			}
		}

		//网关对象为空,则取登陆时记录在玩家身上的网关信息
		JsonObject mtDeviceInfoJson  = new JsonObject() ;
		//加上默认值,保证维护修复前有需要补单的玩家
		if (Tool.isEmpty(mtDeviceInfo)) {
			mtDeviceInfoJson.put("mtDeviceId", "");
			mtDeviceInfoJson.put("mtDeviceIdType", "");
			mtDeviceInfoJson.put("mtBiDeviceId", "");
			mtDeviceInfoJson.put("channel", 0);
			mtDeviceInfoJson.put("platform", 0);
		} else {
			mtDeviceInfoJson = new JsonObject(mtDeviceInfo);
		}

		if (this.deviceidAd.isEmpty()) {
			this.deviceidAd = mtDeviceInfoJson.getString("mtDeviceId","");
		}
		if (this.deviceTypeAd.isEmpty()) {
			this.deviceTypeAd = mtDeviceInfoJson.getString("mtDeviceIdType","");
		}
		if (this.deviceidBi.isEmpty()) {
			this.deviceidBi = mtDeviceInfoJson.getString("mtBiDeviceId","");
		}
		if (this.channel == 0) {
			Object channelObj = mtDeviceInfoJson.containsKey("channel")? mtDeviceInfoJson.getValue("channel") : new Object();
			if (channelObj instanceof  Integer){
				this.channel = mtDeviceInfoJson.getInteger("channel",0);
			}
		}
		if (this.platform == 0) {
			Object platformObj = mtDeviceInfoJson.containsKey("platform")? mtDeviceInfoJson.getValue("platform") : new Object();
			if (platformObj instanceof  Integer){
				this.platform = mtDeviceInfoJson.getInteger("platform",0);
			}
		}


		// 玩家离线时到账取不到gateObj 也取不到记录玩家身上的登陆信息,则取注册时的Platform,channel,和设备id
		if (this.platform == 0) {
			this.platform =  userExtPlatform;
			this.channel = (int) userExtChannel;
		}

	}
	public String getAccountId() {
		return accountId;
	}

	public void setAccountId(String accountId) {
		this.accountId = accountId;
	}

	public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		this.userId = userId;
	}

	public int getPlatform() {
		return platform;
	}

	public void setPlatform(int platform) {
		this.platform = platform;
	}

	public long getChannel() {
		return channel;
	}

	public void setChannel(long channel) {
		this.channel = (int) channel;
	}

	public long getServerId() {
		return serverId;
	}

	public void serServerId(int serverId) {
		this.serverId = serverId;
	}

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public double getMoney() {
		return money;
	}

	public void setMoney(double money) {
		this.money = money;
	}

	public String getLogType() {
		return logType;
	}

	public void setLogType(String logType) {
		this.logType = logType;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getIdfa() {
		return idfa;
	}

	public void setIdfa(String idfa) {
		this.idfa = idfa;
	}

	public String getIdfv() {
		return idfv;
	}

	public void setIdfv(String idfv) {
		this.idfv = idfv;
	}

	public String getImei() {
		return imei;
	}

	public void setImei(String imei) {
		this.imei = imei;
	}
	
	public String getOaid() {
		return oaid;
	}

	public void setOaid(String oaid) {
		this.oaid = oaid;
	}

	public String getAndroidid() {
		return androidid;
	}

	public void setAndroidid(String androidid) {
		this.androidid = androidid;
	}

	public String getRyos() {
		return ryos;
	}

	public void setRyos(String ryos) {
		this.ryos = ryos;
	}

	public String getCaid() {
		return caid;
	}


	public String getLastCaid() {
		return last_caid;
	}

	public String getUa() {
		return ua;
	}

	public String getDeviceId() {
		return deviceidAd;
	}
	public String getDeviceType() {
		return deviceTypeAd;
	}
	public String getDeviceIdBi() {
		return deviceidBi;
	}







}
